package me.zhengjie.modules.rest.intell;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.domain.intellectual.Patent;
import me.zhengjie.modules.service.intell.PatentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

@Api("企业专利信息APi")
@RestController
@RequestMapping("/patent")
@RequiredArgsConstructor
public class PatentController {
    private final PatentService patentService;

    @AnonymousAccess
    @ApiOperation("根据企业名称查询专利信息")
    @GetMapping("/queryPatentByName")
    public List<Patent> queryPatentByName(String name){
        return patentService.queryPatentByName(name);
    }

    @AnonymousAccess
    @ApiOperation("根据条件分页查询专利信息")
    @GetMapping("/queryPatentForPageByConditions")
    public Map<String,Object> queryPatentForPageByConditions(String[] status,String[] type,String[] appTime,String[] pubDate,@RequestParam Integer pageNo,@RequestParam Integer pageSize){
        if(status!=null&&status.length==0){
            status=null;
        }
        if(type!=null&&type.length==0){
            type=null;
        }
        if(appTime!=null&&appTime.length==0){
            appTime=null;
        }
        if(pubDate!=null&&pubDate.length==0){
            pubDate=null;
        }
        Map<String, Object> map=new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("status",status);
        map.put("type",type);
        map.put("appTime",appTime);
        map.put("pubDate",pubDate);
        List<Patent> list=patentService.queryPatentForPageByConditions(map);
        int total=patentService.queryPatentForPageByConditionsToTotal(map);
        map=new HashMap<>();
        map.put("list",list);
        map.put("total",total);
        return map;
    }

    @AnonymousAccess
    @ApiOperation("查询专利状态信息,公开类型，申请日期，专利公开日")
    @GetMapping("/queryPatentType")
    public Map<String, Object> queryPatentType(){
        Map<String, Object> map=new HashMap<>();
        List<String> status=patentService.queryPatentStatus();
        List<String> type=patentService.queryPatentType();
        List<String> AppTime=patentService.queryPatentAppTime();
        List<String> PubDate=patentService.queryPatentPubDate();
        map.put("status",status);
        map.put("type",type);
        map.put("appTime",AppTime);
        map.put("pubDate",PubDate);
        return map;
    }

}

